Insert Horizontal Rule
This feature allows you to insert a horizontal rule into the editor. The code sample demonstrates how to import the HorizontalRule extension, initialize the Tiptap editor with it, and programmatically insert a horizontal rule.
import { HorizontalRule } from '@tiptap/extension-horizontal-rule';
import { Editor } from '@tiptap/core';
const editor = new Editor({
extensions: [
HorizontalRule,
],
});
// To insert a horizontal rule programmatically
editor.chain().focus().setHorizontalRule().run();
Custom Styling for Horizontal Rule
This feature allows you to customize the styling of the horizontal rule. The code sample demonstrates how to extend the HorizontalRule extension to add a custom class to the horizontal rule element, and then initialize the Tiptap editor with this customized extension.
import { HorizontalRule } from '@tiptap/extension-horizontal-rule';
import { Editor } from '@tiptap/core';
const CustomHorizontalRule = HorizontalRule.extend({
renderHTML({ HTMLAttributes }) {
return ['hr', { class: 'custom-horizontal-rule', ...HTMLAttributes }];
},
});
const editor = new Editor({
extensions: [
CustomHorizontalRule,
],
});